@model BarManager.UI.Web.Models.ProductoViewModel

@{ ViewBag.Title = "Producto";}

@using (Html.BeginForm("Save", "Producto"))
{
    @Html.AntiForgeryToken()

    <fieldset class="form-horizontal">
        <legend>Producto</legend>

        @Html.HiddenFor(model => model.Entity.Id)

        <div class="control-group">
            @Html.LabelFor(model => model.Entity.Nombre, new { @class = "control-label" })
            <div class="controls">
                @Html.EditorFor(model => model.Entity.Nombre)
                @Html.ValidationMessageFor(model => model.Entity.Nombre, null, new { @class = "help-inline" })
            </div>
        </div>

        <div class="control-group">
            @Html.LabelFor(model => model.Entity.PrecioVenta, new { @class = "control-label" })
            <div class="controls">
                @Html.EditorFor(model => model.Entity.PrecioVenta)
                @Html.ValidationMessageFor(model => model.Entity.PrecioVenta, null, new { @class = "help-inline" })
            </div>
        </div>

        <div class="control-group">
            @Html.LabelFor(model => model.Entity.PrecioCosto, new { @class = "control-label" })
            <div class="controls">
                @Html.EditorFor(model => model.Entity.PrecioCosto)
                @Html.ValidationMessageFor(model => model.Entity.PrecioCosto, null, new { @class = "help-inline" })
            </div>
        </div>

        <div class="control-group">
            @Html.LabelFor(model => model.Entity.ControlarStock, new { @class = "control-label" })
            <div class="controls">
                @Html.EditorFor(model => model.Entity.ControlarStock)
                @Html.ValidationMessageFor(model => model.Entity.ControlarStock, null, new { @class = "help-inline" })
            </div>
        </div>

        <div id="showStock">
            <div class="control-group">
                @Html.LabelFor(model => model.Entity.StockMinimo, new { @class = "control-label" })
                <div class="controls">
                    @Html.EditorFor(model => model.Entity.StockMinimo)
                    @Html.ValidationMessageFor(model => model.Entity.StockMinimo, null, new { @class = "help-inline" })
                </div>
            </div>

            <div class="control-group">
                @Html.LabelFor(model => model.Entity.Stock, new { @class = "control-label" })
                <div class="controls">
                    @Html.EditorFor(model => model.Entity.Stock)
                    @Html.ValidationMessageFor(model => model.Entity.Stock, null, new { @class = "help-inline" })
                </div>
            </div>
        </div>

        <div class="control-group">
            <label class="control-label">Categoria</label>
            <div class="controls">
                <div class="input-append">
                    @Html.DropDownListFor(model => model.Entity.CategoriaId, new SelectList(Model.Categorias, "Id", "Nombre"), "Sin seleccionar", new { @class = "input-xlarge" })
                    @Html.ActionLink("Nuevo", "List", "Categoria", null, new { @class = "btn" });
                </div>
                @Html.ValidationMessageFor(model => model.Entity.CategoriaId, "Debe seleccionar una categoria")
            </div>
        </div>

        <div class="control-group">
            <label class="control-label">Proveedor</label>
            <div class="controls">
                <div class="input-append">
                    @Html.DropDownListFor(model => model.Entity.ProveedorId, new SelectList(Model.Proveedores, "Id", "Nombre"), "Sin seleccionar", new { @class = "input-xlarge" })
                    @Html.ActionLink("Nuevo", "List", "Proveedor", null, new { @class = "btn" });
                </div>
            </div>
        </div>

        <div class="control-group">
            <div class="controls">
                @Html.ValidationSummary(true)
            </div>
        </div>

        <div class="control-group">
            <div class="controls">
                <button type="submit" class="btn btn-primary">Guardar</button>
                @Html.ActionLink("Cancelar", "List", null, new { @class = "btn" })
            </div>
        </div>
    </fieldset>
}

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")

    <script type="text/javascript">
        $(document).ready(function () {
            if ($("#Entity_ControlarStock").is(':checked'))
                $("#showStock").show();
            else
                $("#showStock").hide();

            $("#Entity_ControlarStock").click(function () {
                if ($(this).is(':checked'))
                    $("#showStock").show();
                else {
                    $("#showStock").hide();
                    $("#Entity_StockMinimo").val("");
                    $("#Entity_Stock").val("");
                    $("#validationStock").val("");
                    $("#validationStockMinimo").val("");
                }
            });
        });
    </script>
}

